﻿#region License
// Author: David Kirkland <davidrkirkland@gmail.com>
// Copyright 2007-2008 Illogikal Software 
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License 
// 
//     http://www.apache.org/licenses/LICENSE-2.0 
//
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
#endregion

#region Using Directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace NetSpider.Policies
{
    /// <summary>
    /// A policy which honors the rules defined in a site's Robots.txt file.
    /// <remarks>See <a href="http://www.robotstxt.org/orig.html">this page</a> for more information.</remarks>
    /// </summary>
    public class RobotsHonoringPolicy : ISpiderPolicy
    {
        private readonly IVisitRepository _visitRepository;
        private readonly IDocumentFetcherFactory _documentFetcherFactory;

        private Dictionary<string, RobotPolicy> _policies = new Dictionary<string, RobotPolicy>();

        public RobotsHonoringPolicy(IVisitRepository visitRepository, IDocumentFetcherFactory documentFetcherFactory)
        {
            _visitRepository = visitRepository;
            _documentFetcherFactory = documentFetcherFactory;
        }

        public PolicyDecision IsVisitAllowed(Uri uri)
        {
            return PolicyDecision.VisitAllowed;
            if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
            {
                string robotsPolicyUrl = "http://www.google.co.uk/robots.txt";
                Uri robotsTxtUri = new Uri(robotsPolicyUrl);

                IDocumentFetcher fetcher = _documentFetcherFactory.GetFetcherForUriScheme(robotsTxtUri.Scheme);
                TextDocument rawPolicy = (TextDocument) fetcher.FetchFrom(robotsTxtUri.ToString());
            }

            return PolicyDecision.VisitAllowed;
        }
    }
}